package com.xinkao.example.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xinkao.example.domain.entity.MytestEntity;
import com.xinkao.example.dao.MytestDao;
import com.xinkao.example.service.MytestService;
import com.xinkao.example.util.CommonUtil;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * 测试
 * @Author 
 * @Date 2021-08-25 17:39:17
 */
@Service("mytestService")
public class MytestServiceImpl extends ServiceImpl<MytestDao, MytestEntity>
        implements MytestService {

    @Resource
    private MytestDao dao;


    /**
     * 分页查询
     */
    @Override
    public JSONObject list4Page(JSONObject jsonObject){
        Page<MytestEntity> page = CommonUtil.getPage(jsonObject);
        dao.list4Page(page, jsonObject);
        return CommonUtil.successPage(page);
    }

    /**
     * 条件查询
     */
    @Override
    public JSONObject listByCondition(JSONObject jsonObject) {
        return CommonUtil.successJson(dao.listByCondition(jsonObject));
    }
    /**
     * 逻辑删除多条记录
     */
    @Override
    @Transactional
    public JSONObject deleteLogic(List<String> list, String userId) {
        this.update(new LambdaUpdateWrapper<>(MytestEntity.class)
                .set(MytestEntity::getDeleteStatus, 1)
                .set(MytestEntity::getUpdateBy, userId)
                .in(MytestEntity::getId, list));
        return CommonUtil.successJson();
    }

    /**
     * 根据id查询详情
     */
    @Override
    public JSONObject queryOneById(String id) {
        return CommonUtil.successJson(dao.queryOneById(id));
    }


    /**
     * 保存或修改
     */
    @Override
    @Transactional
    public JSONObject insertOrEdit(MytestEntity entity) {
        return CommonUtil.successJson(this.saveOrUpdate(entity));
    }

}
